/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import entities.Users;
import javax.persistence.EntityManager;
import javax.persistence.Persistence;
import javax.persistence.Query;

/**
 *
 * @author QUY-THI
 */
public class AccountLogin {

    public Users login(String username, String password) {
        try {
            String pass = EncryptMD5.getHashString(password);
            EntityManager em = Persistence.createEntityManagerFactory("E-AdministrationPU").createEntityManager();
            Query createQuery = em.createQuery("select u from Users u where u.username=:username and u.password=:password");
            createQuery.setParameter("username", username);
            createQuery.setParameter("password", pass);
            return (Users) createQuery.getSingleResult();
        } catch (Exception e) {
            return null;
        }
    }
}
